/*
 * Copyright 2010-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.newpath.core;

import com.google.code.newpath.core.exception.ResourceException;

/**
 * <p>
 * Definition of an interface for Resource Factories.
 * </p>
 * 
 * <p>
 * The <code>{@link Resource}</code> objects are not directly created, but so called 
 * <em>resource factory</em>. This additional level of indirection provides
 * for high flexibility in creation process. For instance: <br/>
 *  1. One implementation of this interface could create new bean resource for each <code>{@link Path}</code> which suffix is '.pb'. <br/>
 *  2. And the other implementation of this interface could create message(string) resource each <code>{@link Path}</code> which suffix is '.msg'.
 * By default, a implementation could cache already created resource and ensure that always
 * the same resource instance of the given <code>{@link Path}</code>.
 * </p>
 * <p>
 * This interface itself is quite simple. There are only two methods for it.
 * One could get resource object. The other could flush match resource which cached in current ResourceFactory.
 * </p>
 * <p>
 * In principle, <em>resource factory</em> doesn't create the actually instance of resource target.
 * It only create the <code>{@link Resource}</code> which is the template of definition for resource target.
 * The instanceTarget method of <code>{@link Resource}</code> provides the only way to create the resource target.
 * </p>
 * <p>
 * And what's the difference between the resource and the resource target? Please reference the <code>{@link Resource}</code>.
 * </P>
 * @author Charlie Zhang
 * @since 2011-1-25
 * @param <T>
 */
public interface ResourceFactory<T extends Resource<?>> {
	
	/**
	 * 
	 * Get Resource by path
	 * 
	 * @param fullPath
	 * @return
	 * @throws ResourceException
	 */
	public T getResource(Path fullPath) throws ResourceException;
	
	/**
	 * 
	 * Get Resource by String type path
	 * 
	 * @param fullPath
	 * @return
	 * @throws ResourceException
	 */
	public T getResource(String fullPath) throws ResourceException;
	
	public void registerCreator(PathMatchPattern filterMathPattern, ResourceCreator creator);
	
	public void registerCreator(String filterPathPattern, ResourceCreator creator);

	public void registerCreator(ResourceCreator creator);
	
	
	/**
	 * Returns path suffixes of this resources in this factory. 
	 * @return
	 */
	public String[] getSuffixes();

}
